package com.jiaoyou.demo.Controller;

import com.jiaoyou.demo.entity.Demand;
import com.jiaoyou.demo.entity.Good;
import com.jiaoyou.demo.service.DemandService;
import com.jiaoyou.demo.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
/**
 *
 * 商品管理控制
 * @author Wang
 *
 **/
@RestController
@RequestMapping("/home")
public class MailController {
    @Autowired
    private GoodService goodService;
    @Autowired
    private DemandService demandService;
    @RequestMapping("/recommend")
    @ResponseBody
    public Object recommend(){/*推荐*/
        int r =new Random().nextInt(goodService.count());//直接随机两个商品
        List<Good> good = goodService.queryAllByLimit(r,2);

        return new JsonResult(good);
    }
    @RequestMapping("/newgoods")//最新商品
    public Object newgoods(){
        List<Good> goods = goodService.queryAllByLimit(0,2);
        return new JsonResult(goods);
    }

    @RequestMapping("/newdemand")//最新需求
    public Object newdemand(){
        List<Demand> demands = demandService.queryAllByLimit(0,2);
        return new JsonResult(demands);
    }

}
